#include <catch2/catch_test_macros.hpp>
#include "BVP.h"

TEST_CASE("regular grid", "[grid]")
{
    BVP2d tmp(
        {0, 0}, 0, [](Point2d)
        { return double(1.0); },
        BoundaryCondition{});
    tmp.Discretization(8);
    double h = 1.0 / 8;
    for (int i = 0; i < 7; ++i)
    {
        for (int j = 0; j < 7; ++j)
        {
            REQUIRE(tmp.getGrid()[7 * i + j] == Point2d{(i + 1) * h, (j + 1) * h});
        }
    }
    // tmp.PrintAdajacancy();
}

TEST_CASE("irregular grid", "[grid]")
{
    BVP2d tmp(
        {0, 0}, 0.5, [](Point2d)
        { return double(1.0); },
        BoundaryCondition{});
    tmp.Discretization(4);
    double h = 1.0 / 4;

    REQUIRE(tmp.getGrid()[0] == Point2d{0.25, 0.5});
    REQUIRE(tmp.getGrid()[1] == Point2d{0.25, 0.75});
    REQUIRE(tmp.getGrid()[2] == Point2d{0.5, 0.25});
    REQUIRE(tmp.getGrid()[3] == Point2d{0.5, 0.5});
    REQUIRE(tmp.getGrid()[4] == Point2d{0.5, 0.75});
    REQUIRE(tmp.getGrid()[5] == Point2d{0.75, 0.25});
    REQUIRE(tmp.getGrid()[6] == Point2d{0.75, 0.5});
    REQUIRE(tmp.getGrid()[7] == Point2d{0.75, 0.75});

    // tmp.PrintAdajacancy();

    tmp.Discretization(8);
    // tmp.PrintAdajacancy();
}

TEST_CASE("check connectness", "[grid]")
{
    BVP2d tmp({0.5, 0.5}, 0.5, nullptr, BoundaryCondition{});

    try
    {
        tmp.Discretization(64);
    }
    catch (std::domain_error)
    {
        std::cout << "Connectness test passed! " << std::endl;
    }
}